package com.atguigu.spzx.model.result;

import lombok.Data;
//统一响应类
@Data
public class Result<T> {
    private Integer code;
    private String message;
    private T data;

    //1、快速创建Result对象的方法
    public static <T> Result setResult(Integer  code , String message , T data){
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }
    public static <T> Result setResult(ResultCodeEnum codeEnum){
        Result<T> result = new Result<>();
        result.setCode(codeEnum.getCode());
        result.setMessage(codeEnum.getMessage());
        result.setData(null);
        return result;
    }
    //2、快速创建成功的Result对象的方法： 200
    public static <T>  Result ok(){
        return Result.setResult(ResultCodeEnum.SUCCESS);
    }
    public static <T>  Result ok(T data){
        return Result.setResult(ResultCodeEnum.SUCCESS.getCode() ,
                ResultCodeEnum.SUCCESS.getMessage(), data);
    }
    //3、快速创建默认失败的Result对象的方法： -1
    public static <T>  Result fail(){
        return Result.setResult(ResultCodeEnum.FAIL);
    }
    //4、链式调用 修改指定属性值的成员方法
    public Result code(Integer code) {
        this.setCode(code);
        return this;
    }
    public Result message(String message) {
        this.setMessage(message);
        return this;
    }
    public Result data(T data) {
        this.setData(data);
        return this;
    }
//    public static void main(String[] args) {
////        Result.fail().setCode(100).set;
//        Result result = Result.fail().code(100).message("hehe").data("1213");
//        System.out.println(result);
//    }
}
